package services

import (
	"github.com/astaxie/beego/orm"
	model "go_hw/models"
)

//private Integer id;
//private String name;
//private Integer count;
//private Integer teacherNums;
//private Set<Teacher> teachers;
//private Set<Course> courses;
//private List<Student> students;
type ClazzVO struct {
	Id          int    `json: "id"`
	Name        string `json:"name"`
	Count       int    `json:"count"`
	TeacherNums int    `json:"teachernums"`
	//Teachers []Teacher
	//Courses []Course
	//Students []Student
}

func init() {

}
func FindClazzVO(pos, rows int) [] ClazzVO {
	//fmt.Println(pos)
	//fmt.Println(rows)
	if pos < 0 {
		pos = 0
	}
	if rows <= 0 {
		rows = 10
	}
	var clazzVOs []ClazzVO
	o := orm.NewOrm()

	classes, _ := model.FindClazzByPage(o, pos, rows)
	for _, v := range *classes {
		clazzVO := ClazzVO{}
		clazzVO.Count = len(v.Students)
		clazzVO.Id = v.Id
		clazzVO.Name = v.Name
		clazzVO.TeacherNums = len(v.Students)
		clazzVOs = append(clazzVOs, clazzVO)
	}
	return clazzVOs
}
func CountClazzAll() int64  {
	o:=orm.NewOrm()
	count :=model.CountClazzAll(o)
	return count
}
func GetByClazzId(id int) (model.Clazz){
	o:=orm.NewOrm()
	clazz , _ :=model.GetClazzById(o,id)
	return *clazz
}